/**
 * <copyright> </copyright>
 * 
 * $Id$
 */
package org.dengues.model.database.impl;

import java.util.Collection;

import org.dengues.model.database.DatabaseDiagram;
import org.dengues.model.database.DatabasePackage;
import org.dengues.model.database.DiagramChild;
import org.dengues.model.database.SectionColumns;
import org.dengues.model.database.SectionFilters;
import org.dengues.model.database.SectionGroups;
import org.dengues.model.database.SectionHavings;
import org.dengues.model.database.SectionSorts;
import org.dengues.model.database.SectionUnions;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc --> An implementation of the model object '<em><b>Diagram</b></em>'. <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#getStatus <em>Status</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#getDbChildren <em>Db Children</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#getConnId <em>Conn Id</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#getWholeSql <em>Whole Sql</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#getSectionColumns <em>Section Columns</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#getSectionFilters <em>Section Filters</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#getSectionGroups <em>Section Groups</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#getSectionSorts <em>Section Sorts</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#getSectionHavings <em>Section Havings</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#getSectionUnions <em>Section Unions</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DatabaseDiagramImpl#isDistinct <em>Distinct</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DatabaseDiagramImpl extends AbstractDBObjectImpl implements DatabaseDiagram {

    /**
     * The default value of the '{@link #getStatus() <em>Status</em>}' attribute.
     * <!-- begin-user-doc --> <!--
     * end-user-doc -->
     * @see #getStatus()
     * @generated
     * @ordered
     */
    protected static final String STATUS_EDEFAULT = null;

    /**
     * The cached value of the '{@link #getStatus() <em>Status</em>}' attribute.
     * <!-- begin-user-doc --> <!--
     * end-user-doc -->
     * @see #getStatus()
     * @generated
     * @ordered
     */
    protected String status = STATUS_EDEFAULT;

    /**
     * The cached value of the '{@link #getDbChildren() <em>Db Children</em>}' containment reference list. <!--
     * begin-user-doc --> <!-- end-user-doc -->
     * 
     * @see #getDbChildren()
     * @generated
     * @ordered
     */
    protected EList dbChildren;

    /**
     * The default value of the '{@link #getConnId() <em>Conn Id</em>}' attribute.
     * <!-- begin-user-doc --> <!--
     * end-user-doc -->
     * @see #getConnId()
     * @generated
     * @ordered
     */
    protected static final String CONN_ID_EDEFAULT = null;

    /**
     * The cached value of the '{@link #getConnId() <em>Conn Id</em>}' attribute.
     * <!-- begin-user-doc --> <!--
     * end-user-doc -->
     * @see #getConnId()
     * @generated
     * @ordered
     */
    protected String connId = CONN_ID_EDEFAULT;

    /**
     * The default value of the '{@link #getWholeSql() <em>Whole Sql</em>}' attribute.
     * <!-- begin-user-doc --> <!--
     * end-user-doc -->
     * @see #getWholeSql()
     * @generated
     * @ordered
     */
    protected static final String WHOLE_SQL_EDEFAULT = null;

    /**
     * The cached value of the '{@link #getWholeSql() <em>Whole Sql</em>}' attribute.
     * <!-- begin-user-doc --> <!--
     * end-user-doc -->
     * @see #getWholeSql()
     * @generated
     * @ordered
     */
    protected String wholeSql = WHOLE_SQL_EDEFAULT;

    /**
     * The cached value of the '{@link #getSectionColumns() <em>Section Columns</em>}' containment reference list.
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @see #getSectionColumns()
     * @generated
     * @ordered
     */
    protected EList sectionColumns;

    /**
     * The cached value of the '{@link #getSectionFilters() <em>Section Filters</em>}' containment reference list.
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @see #getSectionFilters()
     * @generated
     * @ordered
     */
    protected EList sectionFilters;

    /**
     * The cached value of the '{@link #getSectionGroups() <em>Section Groups</em>}' containment reference list. <!--
     * begin-user-doc --> <!-- end-user-doc -->
     * 
     * @see #getSectionGroups()
     * @generated
     * @ordered
     */
    protected EList sectionGroups;

    /**
     * The cached value of the '{@link #getSectionSorts() <em>Section Sorts</em>}' containment reference list. <!--
     * begin-user-doc --> <!-- end-user-doc -->
     * 
     * @see #getSectionSorts()
     * @generated
     * @ordered
     */
    protected EList sectionSorts;

    /**
     * The cached value of the '{@link #getSectionHavings() <em>Section Havings</em>}' containment reference list.
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @see #getSectionHavings()
     * @generated
     * @ordered
     */
    protected EList sectionHavings;

    /**
     * The cached value of the '{@link #getSectionUnions() <em>Section Unions</em>}' containment reference list. <!--
     * begin-user-doc --> <!-- end-user-doc -->
     * 
     * @see #getSectionUnions()
     * @generated
     * @ordered
     */
    protected EList sectionUnions;

    /**
     * The default value of the '{@link #isDistinct() <em>Distinct</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #isDistinct()
     * @generated
     * @ordered
     */
    protected static final boolean DISTINCT_EDEFAULT = false;

    /**
     * The cached value of the '{@link #isDistinct() <em>Distinct</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #isDistinct()
     * @generated
     * @ordered
     */
    protected boolean distinct = DISTINCT_EDEFAULT;

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    protected DatabaseDiagramImpl() {
        super();
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    protected EClass eStaticClass() {
        return DatabasePackage.Literals.DATABASE_DIAGRAM;
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public String getStatus() {
        return status;
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public void setStatus(String newStatus) {
        String oldStatus = status;
        status = newStatus;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, DatabasePackage.DATABASE_DIAGRAM__STATUS, oldStatus, status));
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public EList getDbChildren() {
        if (dbChildren == null) {
            dbChildren = new EObjectContainmentWithInverseEList(DiagramChild.class, this, DatabasePackage.DATABASE_DIAGRAM__DB_CHILDREN, DatabasePackage.DIAGRAM_CHILD__DB_DIAGRAM);
        }
        return dbChildren;
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public String getConnId() {
        return connId;
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public void setConnId(String newConnId) {
        String oldConnId = connId;
        connId = newConnId;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, DatabasePackage.DATABASE_DIAGRAM__CONN_ID, oldConnId, connId));
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public String getWholeSql() {
        return wholeSql;
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public void setWholeSql(String newWholeSql) {
        String oldWholeSql = wholeSql;
        wholeSql = newWholeSql;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, DatabasePackage.DATABASE_DIAGRAM__WHOLE_SQL, oldWholeSql, wholeSql));
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public EList getSectionColumns() {
        if (sectionColumns == null) {
            sectionColumns = new EObjectContainmentEList(SectionColumns.class, this, DatabasePackage.DATABASE_DIAGRAM__SECTION_COLUMNS);
        }
        return sectionColumns;
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public EList getSectionFilters() {
        if (sectionFilters == null) {
            sectionFilters = new EObjectContainmentEList(SectionFilters.class, this, DatabasePackage.DATABASE_DIAGRAM__SECTION_FILTERS);
        }
        return sectionFilters;
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public EList getSectionGroups() {
        if (sectionGroups == null) {
            sectionGroups = new EObjectContainmentEList(SectionGroups.class, this, DatabasePackage.DATABASE_DIAGRAM__SECTION_GROUPS);
        }
        return sectionGroups;
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public EList getSectionSorts() {
        if (sectionSorts == null) {
            sectionSorts = new EObjectContainmentEList(SectionSorts.class, this, DatabasePackage.DATABASE_DIAGRAM__SECTION_SORTS);
        }
        return sectionSorts;
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public EList getSectionHavings() {
        if (sectionHavings == null) {
            sectionHavings = new EObjectContainmentEList(SectionHavings.class, this, DatabasePackage.DATABASE_DIAGRAM__SECTION_HAVINGS);
        }
        return sectionHavings;
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public EList getSectionUnions() {
        if (sectionUnions == null) {
            sectionUnions = new EObjectContainmentEList(SectionUnions.class, this, DatabasePackage.DATABASE_DIAGRAM__SECTION_UNIONS);
        }
        return sectionUnions;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public boolean isDistinct() {
        return distinct;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setDistinct(boolean newDistinct) {
        boolean oldDistinct = distinct;
        distinct = newDistinct;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, DatabasePackage.DATABASE_DIAGRAM__DISTINCT, oldDistinct, distinct));
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case DatabasePackage.DATABASE_DIAGRAM__DB_CHILDREN:
                return ((InternalEList)getDbChildren()).basicAdd(otherEnd, msgs);
        }
        return super.eInverseAdd(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case DatabasePackage.DATABASE_DIAGRAM__DB_CHILDREN:
                return ((InternalEList)getDbChildren()).basicRemove(otherEnd, msgs);
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_COLUMNS:
                return ((InternalEList)getSectionColumns()).basicRemove(otherEnd, msgs);
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_FILTERS:
                return ((InternalEList)getSectionFilters()).basicRemove(otherEnd, msgs);
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_GROUPS:
                return ((InternalEList)getSectionGroups()).basicRemove(otherEnd, msgs);
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_SORTS:
                return ((InternalEList)getSectionSorts()).basicRemove(otherEnd, msgs);
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_HAVINGS:
                return ((InternalEList)getSectionHavings()).basicRemove(otherEnd, msgs);
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_UNIONS:
                return ((InternalEList)getSectionUnions()).basicRemove(otherEnd, msgs);
        }
        return super.eInverseRemove(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public Object eGet(int featureID, boolean resolve, boolean coreType) {
        switch (featureID) {
            case DatabasePackage.DATABASE_DIAGRAM__STATUS:
                return getStatus();
            case DatabasePackage.DATABASE_DIAGRAM__DB_CHILDREN:
                return getDbChildren();
            case DatabasePackage.DATABASE_DIAGRAM__CONN_ID:
                return getConnId();
            case DatabasePackage.DATABASE_DIAGRAM__WHOLE_SQL:
                return getWholeSql();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_COLUMNS:
                return getSectionColumns();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_FILTERS:
                return getSectionFilters();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_GROUPS:
                return getSectionGroups();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_SORTS:
                return getSectionSorts();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_HAVINGS:
                return getSectionHavings();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_UNIONS:
                return getSectionUnions();
            case DatabasePackage.DATABASE_DIAGRAM__DISTINCT:
                return isDistinct() ? Boolean.TRUE : Boolean.FALSE;
        }
        return super.eGet(featureID, resolve, coreType);
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public void eSet(int featureID, Object newValue) {
        switch (featureID) {
            case DatabasePackage.DATABASE_DIAGRAM__STATUS:
                setStatus((String)newValue);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__DB_CHILDREN:
                getDbChildren().clear();
                getDbChildren().addAll((Collection)newValue);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__CONN_ID:
                setConnId((String)newValue);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__WHOLE_SQL:
                setWholeSql((String)newValue);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_COLUMNS:
                getSectionColumns().clear();
                getSectionColumns().addAll((Collection)newValue);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_FILTERS:
                getSectionFilters().clear();
                getSectionFilters().addAll((Collection)newValue);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_GROUPS:
                getSectionGroups().clear();
                getSectionGroups().addAll((Collection)newValue);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_SORTS:
                getSectionSorts().clear();
                getSectionSorts().addAll((Collection)newValue);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_HAVINGS:
                getSectionHavings().clear();
                getSectionHavings().addAll((Collection)newValue);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_UNIONS:
                getSectionUnions().clear();
                getSectionUnions().addAll((Collection)newValue);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__DISTINCT:
                setDistinct(((Boolean)newValue).booleanValue());
                return;
        }
        super.eSet(featureID, newValue);
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public void eUnset(int featureID) {
        switch (featureID) {
            case DatabasePackage.DATABASE_DIAGRAM__STATUS:
                setStatus(STATUS_EDEFAULT);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__DB_CHILDREN:
                getDbChildren().clear();
                return;
            case DatabasePackage.DATABASE_DIAGRAM__CONN_ID:
                setConnId(CONN_ID_EDEFAULT);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__WHOLE_SQL:
                setWholeSql(WHOLE_SQL_EDEFAULT);
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_COLUMNS:
                getSectionColumns().clear();
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_FILTERS:
                getSectionFilters().clear();
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_GROUPS:
                getSectionGroups().clear();
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_SORTS:
                getSectionSorts().clear();
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_HAVINGS:
                getSectionHavings().clear();
                return;
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_UNIONS:
                getSectionUnions().clear();
                return;
            case DatabasePackage.DATABASE_DIAGRAM__DISTINCT:
                setDistinct(DISTINCT_EDEFAULT);
                return;
        }
        super.eUnset(featureID);
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public boolean eIsSet(int featureID) {
        switch (featureID) {
            case DatabasePackage.DATABASE_DIAGRAM__STATUS:
                return STATUS_EDEFAULT == null ? status != null : !STATUS_EDEFAULT.equals(status);
            case DatabasePackage.DATABASE_DIAGRAM__DB_CHILDREN:
                return dbChildren != null && !dbChildren.isEmpty();
            case DatabasePackage.DATABASE_DIAGRAM__CONN_ID:
                return CONN_ID_EDEFAULT == null ? connId != null : !CONN_ID_EDEFAULT.equals(connId);
            case DatabasePackage.DATABASE_DIAGRAM__WHOLE_SQL:
                return WHOLE_SQL_EDEFAULT == null ? wholeSql != null : !WHOLE_SQL_EDEFAULT.equals(wholeSql);
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_COLUMNS:
                return sectionColumns != null && !sectionColumns.isEmpty();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_FILTERS:
                return sectionFilters != null && !sectionFilters.isEmpty();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_GROUPS:
                return sectionGroups != null && !sectionGroups.isEmpty();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_SORTS:
                return sectionSorts != null && !sectionSorts.isEmpty();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_HAVINGS:
                return sectionHavings != null && !sectionHavings.isEmpty();
            case DatabasePackage.DATABASE_DIAGRAM__SECTION_UNIONS:
                return sectionUnions != null && !sectionUnions.isEmpty();
            case DatabasePackage.DATABASE_DIAGRAM__DISTINCT:
                return distinct != DISTINCT_EDEFAULT;
        }
        return super.eIsSet(featureID);
    }

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public String toString() {
        if (eIsProxy()) return super.toString();

        StringBuffer result = new StringBuffer(super.toString());
        result.append(" (status: ");
        result.append(status);
        result.append(", connId: ");
        result.append(connId);
        result.append(", wholeSql: ");
        result.append(wholeSql);
        result.append(", distinct: ");
        result.append(distinct);
        result.append(')');
        return result.toString();
    }

} // DatabaseDiagramImpl
